/*
 * File Name:               UIMutexGroup.cs
 * 
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>

 * Create Date:             2017/06/07
 */

using UnityEngine;
using UnityEngine.EventSystems;

[ExecuteInEditMode]
public class UIMutexGroup : UIBehaviour
{
    private int mOldState = -1;
    public int CurrentState;
    public GameObject[] Childs;

    protected override void Awake()
    {
        if (Childs == null) return;
        foreach (var child in Childs)
        {
            var pos = child.transform.localPosition;
            pos.z = 0;
            child.transform.localPosition = pos;
            child.SetActive(true);
        }
    }

    void LateUpdate()
    {
        if (mOldState == CurrentState)
            return;

        mOldState = CurrentState;

        if (Childs == null) return;
        for (int i = 0; i < Childs.Length; i++)
        {
            var pos = Childs[i].transform.localPosition;

            if (CurrentState == i + 1)
            {
                var c = Childs[i];
                if (!c.activeSelf)
                    c.SetActive(true);
                //pos.z = 0f;
            }
            else
            {
                var c = Childs[i];
                if (c.activeSelf)
                    c.SetActive(false);
                //pos.z = 10000f;
            }

            Childs[i].transform.localPosition = pos;
        }
    }
}
